package LexicographicalNumbers;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Solution {
    public List<Integer> lexicalOrder(int n) {
        List<Integer> list=new ArrayList<>();
        dfs(0,list,n);
        return list;
    }

	private void dfs(int num, List<Integer> list, int n) {
		for (int i=0;i<=9;i++){
			num=num*10+i;
			if (num>0&&num<=n){
				list.add(num);
				dfs(num, list, n);
			}
			num=num/10;
		}
	}
	public static void main(String args[]){
		Solution so=new Solution();
		so.lexicalOrder(234);
	}
}
